package com.sliface.web.core;

public class JsonParser {
	private String jsonStr;
	private int profileIndex;
	private int profileSize;
	private int dataIndex;
	private int mark;

	
	public JsonParser(String source){
		jsonStr=source;
		profileIndex=0;
		if(source!=null && source.length()>0){
			do{
				profileIndex++;
			}while(jsonStr.charAt(profileIndex)!=':');
		}
		profileSize=parseInt(0,profileIndex);
		profileIndex++;
		dataIndex=profileIndex+profileSize;
		
	}
	
	public String nextValue(){
		mark();
		do{
			profileIndex++;
		}while(jsonStr.charAt(profileIndex)!=',');	
		int size=parseInt(mark,profileIndex);
		int oldDataIndex=dataIndex;
		dataIndex=oldDataIndex+size;
		profileIndex++;
		
		return jsonStr.substring(oldDataIndex, dataIndex);
		
	}
	
	private void mark(){
		mark=profileIndex;
	}
	
 
	
	private int parseInt(int start,int end){
		int result=0;
		while(start<end){
			result=result*10+jsonStr.charAt(start++)-48;
		}
		return result;
	}
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String source="5:16,8,xdcarter@163.comasdfasdf";
		JsonParser test=new JsonParser(source);
		String account=test.nextValue();
		String passwd = test.nextValue();

	}

}
